public class Test {
}
class Solution {
    public int maxProfit(int[] prices) {
        int ans = 0;
        int prev_min = prices[0];
        for(int i=1; i<prices.length; i++){
            prev_min = Math.min(prev_min,prices[i-1]);
            ans = Math.max(ans,prices[i]-prev_min);
        }
        return ans;
    }
}
